<? include("header.html"); ?>
<!--页主体开始-->
<script type="text/javascript">
    <? if($login_user_info['u_grade'] > 90){   ?>
        
        var login_user = <?=$login_user?>;
        var base_path = '<?=$base_path?>';
        Ext.Loader.setConfig({enabled: true});
        Ext.onReady(function(){
            Ext.getBody().mask('加载模板中……'); 
            Ext.QuickTips.init();
            var login_user = <?=$login_user?>;
            /*自定义分组前端验证*/
            Ext.apply(Ext.form.field.VTypes, {
                groupregex : function(v){
                    return  /^\+?[1-9][0-9]*$/.test(v);
                },
                groupregexText: '请选择工作组'
            });

            var workgroupStore = Ext.create('Ext.data.Store', {
                //data: <?=$group_rs?>,
                proxy:{
                    type: 'ajax',
                    url: base_path + "index.php?c=usergroup&a=listworkgroup",
                    reader: 'json'
                },
                fields:[{name: 'u_name', type: 'string'},{name: 'u_id', type: 'string'}],
                autoLoad: true
            });
            var groupuserform = new Ext.form.Panel({
                title: '添加工作组',
                width: 300,
                //height: 150,
                autoHeight : true,
                renderTo: 'trxx',
                frame: true,
                bodyStyle: 'padding: 5 5 5 5',
                defaultType: 'textfield',
                buttonAlign: 'center',
                defaults: {
                    autoFitErrors: false,
                    labelSeparator : '：',
                    labelWidth: 80,
                    width: 220,
                    allowBlank: false,
                    blankText: '不允许为空',
                    labelAlign: 'left',
                    msgTarget: 'under'  
                },
                items: [{
                    xtype: 'combo',
                    //vtype: 'groupregex',
                    fieldLabel: '工作组',
                    name: 'workgroup_id',
                    emptyText: '请选择工作组',
                    listConfig:{
                        emptyText: '请选择工作组',
                        maxHeight: 100
                    },
                    triggerAction: 'all',
                    store: workgroupStore,
                    displayField: 'u_name',
                    valueField: 'u_id',
                    queryMode: 'local',
                    forceSelection: true,
                    editable: false,
                },{
                    xtype:'hiddenfield',
                    name: 'login_user_id',
                    value: login_user.u_id
                },{
                    xtype:'hiddenfield',
                    name: 'login_user_name',
                    value: login_user.u_name
                },{
                    xtype:'hiddenfield',
                    name: 'login_user_group',
                    value: login_user.u_parent
                }, {
                    xtype:'textfield',
                    name: 'username',
                    id: 'username',
                    fieldLabel: '姓 名'
                }, {
                    xtype:'textfield',
                    vtype: 'email',
                    name: 'email',
                    id: 'email',
                    fieldLabel: '邮 箱'
                }, {
                    xtype:'radiogroup',
                    id: 'grade',
                    fieldLabel: '权限',
                    columns: 2,
                    vertical: true,
                    items: [
                    { boxLabel: '普通组员', name: 'grade', inputValue: '0', checked: true},
                    { boxLabel: '组管理员', name: 'grade', inputValue: '1'},
                    { boxLabel: '组领导', name: 'grade', inputValue: '2' },
                    { boxLabel: '系统管理员', name: 'grade', inputValue: '100' },
                    { boxLabel: '公司领导', name: 'grade', inputValue: '99' },
                    ]
                }],
                buttons:[{
                    text: '添加',
                    handler: function(){
                        if(groupuserform.form.isValid()){
                            groupuserform.getForm().submit({
                                url: '<?=$base_path?>index.php?c=usergroup&a=addgroupuser',
                                method: 'post',
                                timeout: 30,
                                params: groupuserform.getForm().getValues,
                                success: function(form, action){
                                    Ext.Msg.alert('温馨提示', action.result.msg);
                                },
                                failure: function(form, action){
                                    //console.log(action.result);
                                    Ext.Msg.alert('温馨提示', action.result.msg);
                                }
                            });
                        }
                    }
                }]
            });
        });
        <? }else{ ?>
        Ext.onReady(function(){
            Ext.Msg.show({  
                title:'提示',
                closable: false, 
                msg:'你没有此权限， 请联系系统管理员', 
                icon:Ext.MessageBox.WARNING,
                buttons: Ext.Msg.YESNO,  
            }); 
        })

        <? } ?>
    Ext.getBody().unmask();                 
</script>
<div id="trxx" style="margin-top: 50px;margin-left:250px" ></div>
<!--页主体结束-->
<? include("footer.html"); ?>
